// pages/invitation/invitation.js
var app = getApp(), a = app.requirejs("core");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    type: 0,
    list: [{}],
    unused: 0,
    used: 0,
    rec:"",
    tell:"",
    getListData:'',
    page:1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getListData(0)
    wx.startPullDownRefresh();
  },

  tab: function (e) {
    var type = e.currentTarget.dataset.type;
    this.setData({
      type: e.currentTarget.dataset.type,
      getListData:'',
    })
    this.getListData(type);
  },
  // 监听反馈内容
  rec: function (event) {
    // console.log(event.detail.value);
    this.setData({
      rec:event.detail.value
    })
  },
  // 监听反馈电话
   tell: function (event) {
    // console.log(event.detail.value);
    this.setData({
      tell:event.detail.value
    })
  },
  // 提交反馈消息
  playsale:function(){
    var that = this
    var rec = that.data.rec
    var tell = that.data.tell
    if(rec == ''){
      wx.showToast({
        title: '请输入反馈内容',
        icon:"none",
        duration:2000
      })
      return
    }else if(tell.length!=11){
      wx.showToast({
        title: '请输入正确的联系电话',
        icon:"none",
        duration:2000
      })
      return
    }else{
      a.post("/app/ewei_shopv2_api.php?i=1&r=msg.setymecontent", {
        rec,tell
      }, function(res) {
        console.log(res)
        wx.showToast({
          title: res.msg,
          icon:"none",
          duration:2000
        })
      })
      setTimeout(function(){
        wx.navigateBack({
          delta: 1,
        })
      },2000)
    }
  },
  getListData: function (type) {
    var that = this;
    var page = that.data.page
    that.setData({
      getListData:''
    })
    if(type==3 ){
      return
    }
    // msg.index 原来的
    a.post("/app/ewei_shopv2_api.php?i=1&r=msg", {type,page}, function (res) {
      console.log(res)
      if(res.list.length>0){
        console.lpg(12311111)
        that.setData({
          getListData:that.data.getListData.push(res.list)
        })
      }else{
        console.log(45789)
        that.setData({
          searchLoading: false,
          searchLoadingComplete :true
        })
      }
    })
  },
  // 进入团队详情
  tuandui:function(e){
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/subpage/pages/xiaoxi/tuangou/newdateil?id='+id +"&type="+1,
    })
  },
  // 进入平台详情
  pingtai:function(e){
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/subpage/pages/xiaoxi/tuangou/newdateil?id='+id +"&type="+0,
    })
  },
  // 删除通知
  remove:function(e){
    var that = this
    var id = e.currentTarget.dataset.id;
    var type = e.currentTarget.dataset.type;
    console.log(id,type)
    a.post("/app/ewei_shopv2_api.php?i=1&r=msg.delmsg", {id,type,}, function (res) {
      console.log(res)
      if(res.status==1){
        wx.showToast({
          title: res.msg,
          icon:"none",
          duration:20000
        })
      }
      that.getListData(type)
    })
  },

  tongzhi:function(e){
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: "/pages/xiaoxi/tongzhi/index?id="+id,
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })
  },
  fangkui:function(e){
    var id = e.currentTarget.dataset.id;
    console.log(id);
    wx.navigateTo({
      url: "/pages/xiaoxi/fangkui/index?id=" + id,
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({
      page: 1,
      getListData:[],
      searchLoading: true, //"上拉加载"的变量，默认false，隐藏  
      searchLoadingComplete: false //“没有数据”的变量，默认false，隐藏  
    })
    this.getListData(this.data.type);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (!this.data.searchLoadingComplete){
      var currentPageNo = this.data.page;
      this.setData({
        page: currentPageNo + 1,

      })
      this.getListData(this.data.type);
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})